package com.example.main.login

import androidx.lifecycle.MutableLiveData
import com.example.lib_base.mvvm.BaseViewModel
import com.example.main.entity.LoginEntity
import com.example.main.entity.RegisterEntity
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class LoginViewModel @Inject constructor(private val repo: LoginRepo) : BaseViewModel() {
    val LoginSuccess = MutableLiveData<LoginEntity>()
    val RegisterSuccess = MutableLiveData<RegisterEntity>()
    val ForgetSuccess = MutableLiveData<Any>()

    fun loginlist(username: String, password: String) {
        httpRequest(
            { repo.apiService.login(username, password) }, {
                LoginSuccess.postValue(it)
            })
    }
    fun registerList(username: String, password: String) {
        httpRequest(
            { repo.apiService.getRegister(username, password) }, {
                RegisterSuccess.postValue(it)
            })
    }
    fun forgetPW(userid: Int, newPwd: String) {
        httpRequest(
            { repo.apiService.getForget(userid, newPwd) }, {
                ForgetSuccess.postValue(it)
            })
    }
}